package com.ruoyi.project.wt.auditDaylogQuery.controller;

import java.util.*;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.er.domain.PaeaErError;
import com.ruoyi.project.oms.paeaAuBatch.domain.PaeaAuBatch;
import com.ruoyi.project.oms.paeaAuType.domain.PaeaAuType;
import com.ruoyi.project.oms.paeaAuType.service.IPaeaAuTypeService;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylogQuery;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylog;
import com.ruoyi.project.wt.auditDaylogQuery.service.IWtCheckDaylogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 监督日志Controller
 *
 * @author 魏刚
 * @date 2020-03-18
 */
@Controller
@RequestMapping("/wt/auditDaylogQuery")
public class WtCheckDaylogQController extends BaseController
{
    private String prefix = "wt/auditDaylogQuery";

    @Autowired
    private IWtCheckDaylogService wtCheckDaylogService;
    @Autowired
    private IPaeaAuTypeService paeaAuTypeService;

    @RequiresPermissions("wt:auditDaylogQuery:view")
    @GetMapping()
    public String auditDaylogQuery()
    {
        return prefix + "/auditDaylogQuery";
    }

    /**
     * 查询监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WtCheckDaylogQuery wtCheckDaylogQuery)
    {
        startPage();
        List<WtCheckDaylog> list = wtCheckDaylogService.selectList(wtCheckDaylogQuery);
        return getDataTable(list);
    }

    /**
     * 导出监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WtCheckDaylogQuery wtCheckDaylog)
    {
        List<WtCheckDaylog> list = wtCheckDaylogService.selectList(wtCheckDaylog);
        ExcelUtil<WtCheckDaylog> util = new ExcelUtil<WtCheckDaylog>(WtCheckDaylog.class);
        return util.exportExcel(list, "auditDaylogQuery");
    }
    /**
     * 下载监督日志
     */
    @RequiresPermissions("wt:auditDaylogQuery:downLoad")
    @PostMapping("/downLoad")
    @ResponseBody
    public AjaxResult downLoad(WtCheckDaylog wtCheckDaylog)
    {
        return wtCheckDaylogService.download(wtCheckDaylog);
    }
    /**
     * 新增监督日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存监督日志
     */
    @RequiresPermissions("wt:auditDaylogQuery:add")
    @Log(title = "监督日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.saveOrUpdate(wtCheckDaylog));
    }
    /**
     * 删除监督日志
     */
    @RequiresPermissions("wt:auditDaylogQuery:remove")
    @Log(title = "监督日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wtCheckDaylogService.removeByIds(Arrays.asList(ids.split(","))));
    }
    /**
     * 修改监督日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = wtCheckDaylogService.getById(id);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        return prefix + "/checkDayLogView4Auditing";
    }

    /**
     * 审核监督日志
     */
    @RequiresPermissions("wt:auditDaylogQuery:auditing")
    @Log(title = "审核监督日志", businessType = BusinessType.UPDATE)
    @PostMapping("/auditing")
    @ResponseBody
    public AjaxResult auditing(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.auditing(wtCheckDaylog));
    }
    /**
     * 退回监督日志
     */
    @RequiresPermissions("wt:auditDaylogQuery:auditingBack")
    @Log(title = "审核监督日志", businessType = BusinessType.UPDATE)
    @PostMapping("/auditingBack")
    @ResponseBody
    public AjaxResult auditingBack(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.auditingBack(wtCheckDaylog));
    }
    /**
     * add by lisc 2012-08-23 检查当天是否已经写监督日志了
     * @return
     */
    @RequiresPermissions("wt:auditDaylogQuery:doCheckDayLogExists")
    @Log(title = "监督日志", businessType = BusinessType.INSERT)
    @PostMapping("/doCheckDayLogExists")
    @ResponseBody
    public AjaxResult doCheckDayLogExists()
    {
        String result = wtCheckDaylogService.doCheckDayLogExists();
        return AjaxResult.success(result);
    }
    /**
     * 查看监督详情
     */
    @GetMapping("/showAudit4View/{id}")
    public String showAudit4View(@PathVariable("id") String id, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = wtCheckDaylogService.getById(id);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        List<PaeaAuType> patList = paeaAuTypeService.selectPaeaAuTypeList(new PaeaAuType().setStatus(Long.parseLong("0")));
        Map<String,String> map = new HashMap<String,String>();
        if(null != patList && patList.size() > 0)
        {
            for(int i=0;i<patList.size();i++)
            {
                map.put(patList.get(i).getCode(), patList.get(i).getName());
            }
        }
        mmap.put("paeaAuTypeMap",map);
        mmap.put("method","/queryAudit4View");
        return prefix + "/paeaAuBatchQuery";
    }
    /**
     * 查看监督详情
     */
    @GetMapping("/showAudit4View/{workDate}/{createOper}")
    public String showAudit4View(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        List<PaeaAuType> patList = paeaAuTypeService.selectPaeaAuTypeList(new PaeaAuType().setStatus(Long.parseLong("0")));
        Map<String,String> map = new HashMap<String,String>();
        if(null != patList && patList.size() > 0)
        {
            for(int i=0;i<patList.size();i++)
            {
                map.put(patList.get(i).getCode(), patList.get(i).getName());
            }
        }
        mmap.put("paeaAuTypeMap",map);
        mmap.put("method","/queryAudit4View");
        return prefix + "/paeaAuBatchQuery";
    }
    //随机监督
    @GetMapping("/showRandomAudit4View/{workDate}/{createOper}")
    public String showRandomAudit4View(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        List<PaeaAuType> patList = paeaAuTypeService.selectPaeaAuTypeList(new PaeaAuType().setStatus(Long.parseLong("0")));
        Map<String,String> map = new HashMap<String,String>();
        if(null != patList && patList.size() > 0)
        {
            for(int i=0;i<patList.size();i++)
            {
                map.put(patList.get(i).getCode(), patList.get(i).getName());
            }
        }
        mmap.put("paeaAuTypeMap",map);
        mmap.put("method","/queryRandomAudit4View");
        return prefix + "/paeaAuBatchQuery";
    }
    //人工选择监督
    @GetMapping("/showManAudit4View/{workDate}/{createOper}")
    public String showManAudit4View(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        List<PaeaAuType> patList = paeaAuTypeService.selectPaeaAuTypeList(new PaeaAuType().setStatus(Long.parseLong("0")));
        Map<String,String> map = new HashMap<String,String>();
        if(null != patList && patList.size() > 0)
        {
            for(int i=0;i<patList.size();i++)
            {
                map.put(patList.get(i).getCode(), patList.get(i).getName());
            }
        }
        mmap.put("paeaAuTypeMap",map);
        mmap.put("method","/queryManAudit4View");
        return prefix + "/paeaAuBatchQuery";
    }
    //质量检查量
    @GetMapping("/showReAudit4View/{workDate}/{createOper}")
    public String showReAudit4View(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        List<PaeaAuType> patList = paeaAuTypeService.selectPaeaAuTypeList(new PaeaAuType().setStatus(Long.parseLong("0")));
        Map<String,String> map = new HashMap<String,String>();
        if(null != patList && patList.size() > 0)
        {
            for(int i=0;i<patList.size();i++)
            {
                map.put(patList.get(i).getCode(), patList.get(i).getName());
            }
        }
        mmap.put("paeaAuTypeMap",map);
        mmap.put("method","/queryReAudit4View");
        return prefix + "/paeaAuBatchQuery";
    }
    /**
     * 查询监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryAudit4View")
    @PostMapping("/queryAudit4View")
    @ResponseBody
    public TableDataInfo queryAudit4View(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaAuBatch> paeaAuBatches = wtCheckDaylogService.queryPaeaAuBatchs4View(wtCheckDaylog);
        return getDataTable(paeaAuBatches);
    }
    /**
     * 查询抽查监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryRandomAudit4View")
    @PostMapping("/queryRandomAudit4View")
    @ResponseBody
    public TableDataInfo queryRandomAudit4View(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaAuBatch> paeaAuBatches = wtCheckDaylogService.queryRandomPaeaAuBatchs4View(wtCheckDaylog);
        return getDataTable(paeaAuBatches);
    }
    /**
     * 查询人工选择监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryManAudit4View")
    @PostMapping("/queryManAudit4View")
    @ResponseBody
    public TableDataInfo queryManAudit4View(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaAuBatch> paeaAuBatches = wtCheckDaylogService.queryManPaeaAuBatchs4View(wtCheckDaylog);
        return getDataTable(paeaAuBatches);
    }
    /**
     * 查询人工选择监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryReAudit4View")
    @PostMapping("/queryReAudit4View")
    @ResponseBody
    public TableDataInfo queryReAudit4View(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaAuBatch> paeaAuBatches = wtCheckDaylogService.queryRePaeaAuBatchs4View(wtCheckDaylog);
        return getDataTable(paeaAuBatches);
    }
    /**
     * 重点监控下发督办量
     */
    @GetMapping("/showRegistErrView/{workDate}/{createOper}")
    public String showRegistErrView(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        mmap.put("method", "/queryRegistErrView");
        return prefix + "/paeaErErrorQuery";
    }

    /**
     * 重点监控下发督办量
     */
    @GetMapping("/showDealErrView/{workDate}/{createOper}")
    public String showDealErrView(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        mmap.put("method", "/queryDealErrView");
        return prefix + "/paeaErErrorQuery";
    }
    /**
     * 集中预警量
     */
    @GetMapping("/showRiskErrView/{workDate}/{createOper}")
    public String showRiskErrView(@PathVariable("workDate") String workDate, @PathVariable("createOper") String createOper, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        wtCheckDaylog.setWorkDate(DateUtils.dateTime("yyyy-MM-dd",workDate));
        wtCheckDaylog.setCreateOper(createOper);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        mmap.put("method", "/queryRiskErrView");
        return prefix + "/paeaErErrorQuery";
    }
    /**
     * 查询重点监控下发督办量
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryRegistErrView")
    @PostMapping("/queryRegistErrView")
    @ResponseBody
    public TableDataInfo queryRegistErrView(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaErError> paeaErErrors = wtCheckDaylogService.queryRegistErrView(wtCheckDaylog);
        return getDataTable(paeaErErrors);
    }
    /**
     * 查询重点监控下发督办量
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryDealErrView")
    @PostMapping("/queryDealErrView")
    @ResponseBody
    public TableDataInfo queryDealErrView(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaErError> paeaErErrors = wtCheckDaylogService.queryDealErrView(wtCheckDaylog);
        return getDataTable(paeaErErrors);
    }
    /**
     * 查询重点监控下发督办量
     */
    @RequiresPermissions("wt:auditDaylogQuery:queryRiskErrView")
    @PostMapping("/queryRiskErrView")
    @ResponseBody
    public TableDataInfo queryRiskErrView(WtCheckDaylog wtCheckDaylog)
    {
        startPage();
        List<PaeaErError> paeaErErrors = wtCheckDaylogService.queryRiskErrView(wtCheckDaylog);
        return getDataTable(paeaErErrors);
    }
}
